//
//  LCRegisterViewController.m
//  lechuang
//
//  Created by Mr_hi on 2023/4/3.
//  Copyright © 2023 Mooyi. All rights reserved.
//

#import "LCRegisterViewController.h"
#import "XWXAllXieYiController.h"

#import "LCLoginService.h"
#import "LCTabBarViewController.h"

@interface LCRegisterViewController ()

@property (weak, nonatomic) IBOutlet UITextField *mobTfl;
@property (weak, nonatomic) IBOutlet UITextField *pswdTfl;
@property (weak, nonatomic) IBOutlet UITextField *surePswdTfl;
@property (weak, nonatomic) IBOutlet UITextField *codeTfl;
@property (weak, nonatomic) IBOutlet UITextField *shareCodeTfl;
@property (weak, nonatomic) IBOutlet UIButton *getYZMBtn;
@property (weak, nonatomic) IBOutlet UIButton *agreeBtn;

@end

@implementation LCRegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (IBAction)getYZMBtnClicked:(UIButton *)sender {
    if (self.mobTfl.text.length <= 0) {
        [self showErrorText:@"请输入手机号码"];
    } else if ([NSString isMobileNumber:self.mobTfl.text] == NO) {
        [self showErrorText:@"请输入正确格式的手机号"];
    } else {
        [self showText:@"获取验证码中..."];
        [LCLoginService sendSessionCodeWithMobStr:self.mobTfl.text CodeType:@"REGISTER" Block:^(BOOL isSuccess) {
            if (isSuccess) {
                [sender startWithTime:60 title:@"重新获取" countDownTitle:@"s" mainColor:nil countColor:nil];
                [self dismissLoading];
            }
        }];
    }
}

- (IBAction)registerBtnAction:(UIButton *)sender {
    if (self.mobTfl.text.length <= 0) {
        [self showErrorText:self.mobTfl.placeholder];
    } else if ([NSString isMobileNumber:self.mobTfl.text] == NO) {
        [self showErrorText:@"请输入正确格式的手机号"];
    } else if (self.pswdTfl.text.length <= 0) {
        [self showErrorText:self.pswdTfl.placeholder];
    } else if (self.surePswdTfl.text.length <= 0) {
        [self showErrorText:self.surePswdTfl.placeholder];
    } else if (![self.surePswdTfl.text isEqualToString:self.pswdTfl.text]) {
        [self showErrorText:@"两次输入的密码不一致"];
    } else if (self.codeTfl.text.length <= 0) {
        [self showErrorText:self.codeTfl.placeholder];
    } else if (self.agreeBtn.isSelected == NO) {
        [self showErrorText:@"请勾选同意《用户协议》和《隐私政策》"];
    } else {
        [LCLoginService registerWithMobStr:self.mobTfl.text Pswd:self.pswdTfl.text Captcha:self.codeTfl.text ShareCode:self.shareCodeTfl.text Block:^(BOOL isSuccess) {
            if (isSuccess) {
                [self.window setBackgroundColor:[UIColor whiteColor]];
                LCTabBarViewController *tabbar = [[LCTabBarViewController alloc] init];
                self.window.rootViewController = tabbar;
                [self.window makeKeyAndVisible];
            }
        }];
    }
}

- (IBAction)backAction:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)agreeBtnAction:(UIButton *)sender {
    sender.selected = !sender.selected;
}

- (IBAction)lookXieYiAction:(UIButton *)sender {
    XWXAllXieYiController *webVC = [XWXAllXieYiController new];
    webVC.tileStr = @"《用户协议》";
    webVC.urlStr = URLSingleWeb(@"1000007");
    [self presentViewController:webVC animated:YES completion:nil];
}

- (IBAction)lookYinSiAction:(UIButton *)sender {
    XWXAllXieYiController *webVC = [XWXAllXieYiController new];
    webVC.tileStr = @"《隐私协议》";
    webVC.urlStr = URLSingleWeb(@"1000006");
    [self presentViewController:webVC animated:YES completion:nil];
}

@end
